﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace Medianamik.UI.Controls
{
    /// <summary>
    /// Classe abstraite qui sert à ajouter un validateur de type au contrôle Médianamik
    /// </summary>
    public abstract class TypeTextBox : SingleLineTextBox
    {
        public TypeTextBox()
        {
            TypeValidator = new CompareValidator();
        }

        /// <summary>
        /// Ainsi publique pour donner accès à la personnalisation du contrôle validateur.
        /// </summary>
        public CompareValidator TypeValidator;

        public abstract ValidationDataType CompareType { get; }

        protected override void CreateControlHierarchy(bool pUseDataSource)
        {
            Controls.Add(TypeValidator);

            if (!DataBound)
            {
                TypeValidator.Type = CompareType;
                TypeValidator.Operator = ValidationCompareOperator.DataTypeCheck;
                TypeValidator.Display = ValidatorDisplay.None;
                TypeValidator.ControlToValidate = ControlToValidateId;
                TypeValidator.ErrorMessage = Label + " " + INVALID;
                TypeValidator.ValidationGroup = ValidationGroupName;
                TypeValidator.EnableClientScript = EnableClientScriptValidation;
            }

            base.CreateControlHierarchy(pUseDataSource);
        }
    }
}
